'''
文件的读取
1). 创建文件data.txt, 文件共100000行, 每行存放一个1～100之间的整数.
2). 找出文件中数字出现次数最多的10个数字， 写入文件mostNum.txt;

    {
        num:time
    }


'''
import  random
from collections import Counter


def createFile():
    with open("f1000.txt","w") as f:
        for i in range(100000):
            f.write(str(random.randint(1,100))+"\r")

def getNimTimes():
    numDic = {}
    with open("f1000.txt", "r") as f:
        for line in f:
            num = int(line)
            numDic[num] = numDic.get(num,0) + 1
    # print(numDic)
    dd = Counter(numDic)
    with open("mostNum.txt","w",encoding="utf-8") as mostNumFile:
        for tu in dd.most_common(10):
            # print(tu)
            mostNumFile.write(f"数字:{tu[0]},出现的次数:{tu[1]}\r\n")

if __name__ == '__main__':
    createFile()
    getNimTimes()